from random import randint

f_math = open("math.txt", 'a+')
f_key = open("key.txt", 'a+')
ques_num = eval(input("请输入出题数量："))
f_math.write("22道混合加减法题：\n")
f_key.write("22道混合加减法题（带答案）：\n")


def symbol(minus,sub):
    if minus < sub:  # 保证结果不出现负数
        return '+'
    elif randint(0,1):  # 随机生成加减法题
        return '+'
    else:
        return '-'


for i in range(ques_num):
    minuend = randint(0, 100)
    subtrahend = randint(0, 100 - minuend)  # 保证加减法结果小于等于100
    question = str(minuend) + '\t' + symbol(minuend,subtrahend) + '\t' + str(subtrahend) + '\t'
    f_math.write(question + '=\n')
    f_key.write(question + '=' + str(eval(question)) + '\n')

f_math.seek(0)
f_key.seek(0)
print(f_math.read())
print(f_key.read())
